<template>
	<view class="apps">
		<uv-loading-page :loading="load" loading-text="加载中..." font-size="24rpx"></uv-loading-page>
		<view class="content"  v-if="is_auth == 0">
			<view class="head">{{is_show == 0?`新兴产业协会邀请您填写基本信息`:`新兴产业协会邀请您完善信息`}}</view>
			<uv-form labelPosition="left" labelWidth="80" :model="form" :rules="rules" ref="form">
				
				<uv-form-item label="姓名" prop="nickname" required borderBottom v-if="is_show == 0">
					<uv-input v-model="form.nickname" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="手机号" prop="form_20008" required borderBottom  v-if="is_show == 0">
					<uv-input v-model="form.form_20008" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="企业名称" prop="form_20001" required borderBottom  v-if="is_show == 0">
					<uv-input v-model="form.form_20001" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="纳税识别号" prop="form_20009" required borderBottom  v-if="is_show == 1">
					<uv-input v-model="form.form_20009" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="公司职务" prop="form_20006" required borderBottom @click="showSelect('form_20006')"  v-if="is_show == 0">
					<uv-input v-model="form.form_20006" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="所属行业" prop="form_20012" required borderBottom @click="showSelect('form_20012')">
					<uv-input v-model="form.form_20012" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="推荐人" prop="form_20020" borderBottom >
					<uv-input v-model="form.form_20020" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="企业类型" prop="form_20011" required borderBottom @click="showSelect('form_20011')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20011" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				
				<uv-form-item label="企业规模" prop="form_20010" required borderBottom @click="showSelect('form_20010')"   v-if="is_show == 1">
					<uv-input v-model="form.form_20010" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				
				<uv-form-item label="纳税登记" prop="form_20013" required borderBottom @click="showSelect('form_20013')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20013" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="纳税信用" prop="form_20014" required borderBottom @click="showSelect('form_20014')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20014" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="营业收入" prop="form_20015" required borderBottom @click="showSelect('form_20015')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20015" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="进出口企业" prop="form_20016" required borderBottom @click="showSelect('form_20016')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20016" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="跨境电商" prop="form_20017" required borderBottom @click="showSelect('form_20017')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20017" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="科技型企业" prop="form_20018" required borderBottom @click="showSelect('form_20018')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20018" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-form-item label="科技型范围" prop="form_20019" borderBottom @click="showSelect('form_20019')"  v-if="is_show == 1">
					<uv-input v-model="form.form_20019" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
					</uv-input>
					<template v-slot:right>
						<uv-icon name="arrow-right"></uv-icon>
					</template>
				</uv-form-item>
				<uv-button type="primary" text="确认提交" customStyle="margin-top: 10px" @click="submit"></uv-button>
				
			</uv-form>	
		</view>
		<view class="info"  v-else>
			<view class="f18">新兴产业协会</view>
			<view class="f24">欢迎您</view>
		</view>
		<uv-picker ref="picker" :columns="columns" keyName="lable" @confirm="confirm"></uv-picker>
	</view>
</template>

<script>
	let app;
	export default {
		data() {
			return {
				load:true,
				submitStatus:false,
				is_auth:'',
				is_show:'',
				formList:[],
				columns:[],
				rules: {},
				member:{
					nickname:'',
					user_id:'',
					department_id:1,
					form_20008:'',
					form_20001:'',
					form_20009:'',
					form_20006:'',
					form_20003:'',
					form_20004:'',
					form_20010:'',
					form_20020:'',
					form_20011:'',
					form_20012:'',
					form_20013:'',
					form_20014:'',
					form_20015:'',
					form_20016:'',
					form_20017:'',
					form_20018:'',
					form_20019:'',
					is_auth:0,
				},
				form:{
					nickname:'',
					user_id:'',
					department_id:1,
					form_20008:'',
					form_20001:'',
					form_20009:'',
					form_20006:'',
					form_20003:'',
					form_20004:'',
					form_20010:'',
					form_20020:'',
					form_20011:'',
					form_20012:'',
					form_20013:'',
					form_20014:'',
					form_20015:'',
					form_20016:'',
					form_20017:'',
					form_20018:'',
					form_20019:'',
					is_auth:0,
				}
			}
		},
		onLoad(opt) {
			app = this;
			const code = opt.code|| '';
			this.getForm();
			this.login(code);
			//app.is_auth=0;
			//app.is_show =1;
			//app.load =false;
			
			
		},
		methods: {
			login(code){
				app.request({
					url:'/login',
					data:{code:code},
					success:function(rlt){
						if(rlt.code == 1){
							app.load =false;
							app.is_show = rlt.data.is_show;
							app.is_auth = rlt.data.is_auth;
							app.member = Object.assign(app.member,rlt.data);
							app.form = Object.assign(app.form,rlt.data);
							if(app.is_show == 0){
								app.rules={
									nickname:[{
										required: true,
										message: '请填写姓名',
										trigger: ['blur', 'change']
									}],
									form_20008:[{
										required: true,
										message: '请填写手机',
										trigger: ['blur', 'change']
									}],
									form_20001:[{
										required: true,
										message: '请填写企业',
										trigger: ['blur', 'change']
									}],
									
									form_20006:[{
										required: true,
										message: '请选择公司职务',
										trigger: ['blur', 'change']
									}],
									form_20012:[{
										required: true,
										message: '请选择所属行业',
										trigger: ['blur', 'change']
									}],
								};
							}
							if(app.is_show == 1){
								app.rules={
									form_20009:[{
										required: true,
										message: '请填写纳税识别码',
										trigger: ['blur', 'change']
									}],
									form_20011:[{
										required: true,
										message: '请选择企业类型',
										trigger: ['blur', 'change']
									}],
									form_20010:[{
										required: true,
										message: '请选择企业规模',
										trigger: ['blur', 'change']
									}],
									form_20013:[{
										required: true,
										message: '请选择纳税登记',
										trigger: ['blur', 'change']
									}],
									form_20014:[{
										required: true,
										message: '请选择纳税信用',
										trigger: ['blur', 'change']
									}],
									form_20015:[{
										required: true,
										message: '请选择营业收入',
										trigger: ['blur', 'change']
									}],
									form_20016:[{
										required: true,
										message: '请选择进出口企业',
										trigger: ['blur', 'change']
									}],
									form_20017:[{
										required: true,
										message: '请选择跨境电商',
										trigger: ['blur', 'change']
									}],
									form_20018:[{
										required: true,
										message: '请选择科技型企业',
										trigger: ['blur', 'change']
									}],
									
								};
								app.member.is_auth = 1;
								for(let key in app.member){
									if(app.member[key] == 0){
										app.form[key]='';
									}else{
										app.formList[key]?.forEach((item)=>{
											if(item.id == app.member[key]){
												app.form[key]=item.lable;
											}
										})
									}
									
								}
							}
						}else{
							alert('登录认证错误，请重新登录');
						}
					}
				});
			},
			async getForm(){
				
			 await app.request({
					url:'/formitem',
					success:function(rlt){
						app.formList =rlt.data;
					}
				});
				
			},
			
			showSelect(item){
				this.$refs.picker.setColumns([this.formList[item]]);
				this.$refs.picker.open();
			},
			confirm(e) {
				let key = e.value[0].code;
				this.member[key] = e.value[0].id;
				this.form[key] = e.value[0].lable;
			},
			submit(){
				console.log(app.submitStatus);
				if(app.submitStatus){
					return;
				}
				this.$refs.form.validate()
				.then(res => {
					app.submitStatus =true;
					app.member.form_20001 = app.form.form_20001;
					app.member.form_20008 = app.form.form_20008;
					app.member.form_20009 = app.form.form_20009;
					app.member.form_20020 = app.form.form_20020;
					app.request({
						url:"/userverify",
						data:app.member,
						load:true,
						loadTxt:'请稍后...',
						success:function(rlt){
							app.submitStatus = true;
							console.log(rlt);
						}
					})
				}).catch(errors => {
					console.log(errors);
				})
			}
		}
	}
</script>
<style scoped>
.content{display:flex; flex-direction: column; padding:20rpx 20rpx 0 30rpx;}
.head{font-size: 17px;padding:5px 10px;color:#666;margin-bottom: 15rpx; font-weight: 400;}
.info{display: flex; flex-direction: column; padding-top: 100px;}
.f18{font-size: 16px;padding: 10px; display: flex; justify-content: center;color: #000;}
.f24{font-size: 20px;padding: 10px; display: flex; justify-content: center;color:#000}
</style>
